Repository navigation
Conversation
Relates to google#3169. Restrict the legacy EOFException fallback in Gson.fromJson(JsonReader, TypeToken) and Streams.parse(JsonReader) to reader.getStrictness() != Strictness.STRICT. Behavior changes when effective strictness is Strictness.STRICT: - Empty, whitespace-only, and BOM-only documents throw JsonSyntaxException instead of returning null / JsonNull.INSTANCE (RFC 8259 §2). - Truncated mid-document input passed to Gson.fromJson(JsonReader, ...) or JsonParser.parseReader(JsonReader) throws JsonSyntaxException instead of returning null / JsonNull.INSTANCE. - TreeTypeAdapter (JsonDeserializer) throws JsonSyntaxException on empty input when read with a STRICT JsonReader. Default Gson, LEGACY_STRICT, LENIENT, and Gson.fromJson((String) null, ...) are unchanged.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Purpose
Relates to #3169.
Description
I ran the RFC 8259 cases from the benchmark in #3169 with
Strictness.STRICT(and strict UTF-8 decoding). Four cases that should fail still pass:json-8259-empty("")jts-8259-n_structure_no_data("")jts-8259-n_single_space(" ")jts-8259-n_structure_UTF8_BOM_no_data("\uFEFF")JsonReaderalready throwsEOFExceptionfor these, butGson.fromJsonandJsonParser.parseReadercatch it and returnnullfor compatibility with Gson 1.5. This PR keeps that fallback for every mode exceptSTRICT. ModeSTRICTwill now throwJsonSyntaxException.Behavior change for truncated mid-document reads in
STRICTmode: they would previously returnnullsinceisEmptywastruewhenreader.peek()threwEOFException. Now they throwJsonSyntaxException.This will break anyone on
STRICTwho relies on an empty body turning intonull.Checklist
mvn clean verify javadoc:jarpasses without errors